/*
 * EscuelaVistaPrincipal.java
 */

package es.uma.masterinftel.colegio_inftel.vistas;

import es.uma.masterinftel.colegio_inftel.modelo.dao.EscuelaModeloDAO;
import es.uma.masterinftel.colegio_inftel.modelo.dto.EscuelaModeloDTO;
import es.uma.masterinftel.colegio_inftel.utilidades.*;
import java.awt.event.ActionListener;
import javax.swing.event.*;
import javax.swing.DefaultComboBoxModel;


/**
 * Vista para la muestra de los datos de los alumnos en una tabla.
 * 
 * @author Manuel Valls
 * @version v1.0 Diciembre-2011
 */
public class EscuelaVistaPrincipal extends javax.swing.JFrame {
    
    private EscuelaModeloDAO m_modelo;
    EscuelaModeloDTO dto = new EscuelaModeloDTO();
    DefaultComboBoxModel comboModelo = new DefaultComboBoxModel();
    DefaultComboBoxModel comboModeloGrupo = new DefaultComboBoxModel();
    DefaultComboBoxModel comboModeloAsignatura = new DefaultComboBoxModel();
    /**
     * Booleano para controlar si un profesor es Jefe de Estudios o no
     */
    public boolean bJefeDeEstudios;
    private Integer idProfesor;
    
    /**
     * Metodo get
     * @return Id del profesor
     */
    public Integer getIdProfesor() {
        return idProfesor;
    }
    
    /**
     * Constructor de la clase
     * @param modelo Modelo para la tabla 
     */
    public EscuelaVistaPrincipal(EscuelaModeloDAO modelo) {
        
        m_modelo = modelo;
        
        dto.setId_cursos_fk(1);
        dto.setId_grupo_kf(1);
        dto.setCodasignatura_fk(1);
         
        m_modelo.rellenaTabla(dto);
       
        initComponents();
        
        this.setLocationRelativeTo(null); //centramos la ventana en pantalla
     
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        comboCurso = new javax.swing.JComboBox();
        comboGrupo = new javax.swing.JComboBox();
        comboAsignatura = new javax.swing.JComboBox();
        curso = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        textNombre = new javax.swing.JTextField();
        btBuscar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        btEstadisticas = new javax.swing.JButton();
        btCalificaciones = new javax.swing.JButton();
        btIncidencias = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel5.setBackground(new java.awt.Color(255, 255, 254));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel1.setText("Profesor:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 13));
        jLabel2.setText("Año Escolar:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 2, 13));
        jLabel3.setForeground(new java.awt.Color(140, 140, 140));
        jLabel3.setText("Mónica Trella");

        jLabel4.setFont(new java.awt.Font("Tahoma", 2, 13));
        jLabel4.setText("2011");

        jLabel5.setFont(new java.awt.Font("Lucida Grande", 0, 48));
        jLabel5.setForeground(new java.awt.Color(152, 151, 151));
        jLabel5.setText("COLEGIO INFTEL");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 322, Short.MAX_VALUE)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel4))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)))
                .addGap(29, 29, 29))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel4))
                .addContainerGap(33, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap(27, Short.MAX_VALUE)
                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23))
        );

        curso.setText("Curso");

        jLabel6.setText("Grupo");

        jLabel7.setText("Asignatura");

        jLabel8.setText("Buscar alumno:");

        btBuscar.setText("Buscar");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(textNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 355, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btBuscar))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(curso)
                            .addComponent(comboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(comboGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(comboAsignatura, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(467, 467, 467))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(comboAsignatura, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboGrupo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(curso)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(41, 41, 41)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(textNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btBuscar))
                .addGap(126, 126, 126))
        );

        comboCurso.setModel(comboModelo);
        comboGrupo.setModel(comboModeloGrupo);
        comboAsignatura.setModel(comboModeloAsignatura);

        btEstadisticas.setText("Ver Estadísticas");

        btCalificaciones.setText("Editar calificaciones");

        btIncidencias.setText("Editar Incidencias");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btEstadisticas)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 444, Short.MAX_VALUE)
                .addComponent(btCalificaciones)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btIncidencias)
                .addGap(81, 81, 81))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(25, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btEstadisticas)
                    .addComponent(btCalificaciones)
                    .addComponent(btIncidencias))
                .addContainerGap())
        );

        jTable1.setModel(m_modelo.modelo);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getColumn(10).setMaxWidth(0);
        jTable1.getColumnModel().getColumn(10).setMinWidth(0);
        jTable1.getColumnModel().getColumn(10).setPreferredWidth(0);
        jTable1.getColumnModel().getColumn(11).setMaxWidth(0);
        jTable1.getColumnModel().getColumn(11).setMinWidth(0);
        jTable1.getColumnModel().getColumn(11).setPreferredWidth(0);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                    .addGap(34, 34, 34)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                    .addGap(39, 39, 39)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 1000, javax.swing.GroupLayout.PREFERRED_SIZE)))
            .addGroup(layout.createSequentialGroup()
                .addGap(15, 15, 15)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

   
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btBuscar;
    private javax.swing.JButton btCalificaciones;
    private javax.swing.JButton btEstadisticas;
    private javax.swing.JButton btIncidencias;
    public javax.swing.JComboBox comboAsignatura;
    public javax.swing.JComboBox comboCurso;
    public javax.swing.JComboBox comboGrupo;
    private javax.swing.JLabel curso;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    public javax.swing.JTable jTable1;
    private javax.swing.JTextField textNombre;
    // End of variables declaration//GEN-END:variables
 
  /**
     * Devuelve el curso seleccionado
     * @return Curso seleccionado
     */ 
   public int getCurso() {
       return comboCurso.getSelectedIndex()+1;
    }
   
   /**
    * Devuelve el grupo seleccionado
    * @return Grupo seleccionado
    */
   public int getGrupo(){
   return comboGrupo.getSelectedIndex()+1;
   }
   
   /**
    * Devuelve la asignatura seleccionada
    * @return Asignatura seleccionada
    */
   public int getAsignatura(){
   return comboAsignatura.getSelectedIndex()+1;
   }
   
   /**
    * Devuelve el item del curso seleccionado
    * @return Item del curso seleccionado
    */
   public Object getCursoItem(){
   return comboCurso.getSelectedItem();
   }
   
   /**
    * Devuelve el item del grupo seleccionado
    * @return Item del grupo seleccionado
    */
   public Object getGrupoItem(){
   return comboGrupo.getSelectedItem();
   }
   
   /**
    * Devuelve el item de la asignatura seleccionada
    * @return Item de la asignatura seleccionada
    */
   public Object getAsignaturaItem(){
   return comboAsignatura.getSelectedItem();
   }
   
   /**
    * Devuelve la cadena de texto escrita en el campo de texto
    * @return Nombre de la persona
    */
   public String getNombre(){
   return textNombre.getText();
   }
   /**
    * Devuelve el número de la fila seleccionada
    * @return Número de la fila seleccionada
    */
   public int getFila(){
   return jTable1.getSelectedRow();
   }
   
   /**
    * Obtiene el valor de una celda
    * @param rowIndex Fila de la tabla
    * @param colIndex Columna de la tabla
    * @return Valor de la celda
    */
    public Object getTableData(int rowIndex, int colIndex){
    return jTable1.getModel().getValueAt(rowIndex, colIndex);
    }  
    
    /**
     * Modifica el valor de la celda de la tabla
     * @param dato Valor a introducir en la celda
     * @param rowIndex Fila de la tabla
     * @param colIndex Columna de la tabla
     */
     public void setTableData(double dato,int rowIndex, int colIndex){
     m_modelo.modelo.setValueAt(dato, rowIndex, colIndex);
    }
     
      /**
      * Acción para buscar alumnos por curso,grupo y asignatura
      * @param bus Acción
      */
    public void addSearchListener(ActionListener bus) {
        btBuscar.addActionListener(bus);
    }
    
    /**
     * Acción para filtrar alumnos por nombre y apellidos
     * @param name Acción
     */
    public void addFilterName(DocumentListener name){
        textNombre.getDocument().addDocumentListener(name);
    }

    /**
     * Accion para mostrar el formulario de Anotar Notas
     * @param a Acción
     */
    public void addAnotarNotasListener(ActionListener a){
        btCalificaciones.addActionListener(a);
    }
    
    /**
     * Acción para mostrar el formulario de Anotar Incidencias
     * @param a Acción
     */
    public void addAnotarIncidenciasListener(ActionListener a){
        btIncidencias.addActionListener(a);
    }
    
    /**
     * Acción para mostrar el formulario de Estadísticas
     * @param a Acción
     */
    public void addVerEstadisticasListener(ActionListener a){
    btEstadisticas.addActionListener(a);
    }
    
    /**
     * Acción para ajustar los combos según el grupo seleccionado
     * @param a Acción
     */
    public void addComboListener(ActionListener a){
    comboCurso.addActionListener(a);
    }
    
    /**
     * Método para saber si un profesor es jefe de estudios o no
     * @param rolUsuario Rol de usuario
     * @param idProfesor  Id del profesor
     */
    public void setRolJefeDeEstudios(Integer rolUsuario,Integer idProfesor) {
      
        bJefeDeEstudios = (rolUsuario == Constantes.ROL_JEFE_DE_ESTUDIOS);
        this.idProfesor = idProfesor;
    }     
}
